package com.minelx.sequence.pattern;

import com.minelx.sequence.core.Match;
import com.minelx.sequence.core.ReturnMatcher;
import com.minelx.sequence.core.StringScanner;

public class SingleCharMatcher implements ReturnMatcher<ReturnMatcher<?, StringScanner>, StringScanner> {
	private static final String ESCAPE = "\\";

	@Override
	public boolean isMatch(StringScanner clue) {
		return !clue.isEmpty()
				&& !clue.exists("}")
				// FIXME 2021/7/12  wait for me!!!     is there any better solution?
				;
	}

	@Override
	public ReturnMatcher<?, StringScanner> onMatched(StringScanner clue) {
		clue.pass(ESCAPE);
		return Match.character(clue.nextChar());
	}
}
